﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.Core.DomainModel;

namespace MethodWorx.Core.DomainModel
{
    public class StubUnitOfWorkFactory : IUnitOfWorkFactory
    {
        private List<StubUnitOfWork> unitsOfWork = new List<StubUnitOfWork>();
        private Dictionary<Type, string> uniqueKeyViolations = new Dictionary<Type, string>();

        #region IUnitOfWorkFactory Members

        public IUnitOfWork Begin()
        {
            unitsOfWork.Add(new StubUnitOfWork(this.uniqueKeyViolations));

            return unitsOfWork.Last();
        }

        public IEnumerable<StubUnitOfWork> UnitsOfWork
        {
            get { return unitsOfWork;  }
        }


        #endregion

        public void ThrowUniqueKeyViolationExceptionWhenAdding<T>(string property )
        {
            this.uniqueKeyViolations.Add(typeof(T), property);
        }
    }
}
